<script type="text/javascript" src="{APP_THEME_DIR}/layui/layui.all.js?v=v2.5.4"></script>
<script type="text/javascript" src="{APP_THEME_DIR}/js/comm.js?v=v2.0.0"></script>
<script type="text/javascript" src="{APP_THEME_DIR}/js/mylayui.js?v=v3.0.2"></script>
 <!-- @mk-tip -->
<script type="text/javascript" src="{APP_THEME_DIR}/js/jquery.form.js?v=v1.0.0"></script>
<script>
	$(document).ready(function() {
	    $('form:not(#contentForm)').ajaxForm({
	        success:  comEdit,
	        dataType: 'json'
	    });
	    $('#contentForm').ajaxForm({
	        success:  comDo,
	        dataType: 'json'
	    });
	});

	// 表单提交
	function comEdit(data){
	    if (data.code == 1) {
	    	var urlStr1 = window.location.search.match('[^/]+(?!.*/)')[0];
	    	var urlStr2 = window.location.search;
	    	if ($.isNumeric(urlStr1)) {
	    		layer.confirm(data.data, {
	    		    icon:1,
	    		    btn: ['继续添加','返回列表'] //按钮
	    		}, function(){
	                window.location.reload();
	                return false;
	            }, function(){
	                // console.log(window.location.hash);
	                if (window.location.hash) {
	                    window.location.href = "{php}echo $_SERVER['REQUEST_URI']{/php}";
	                } else {
	                    window.history.back(-1);
	                }
	                return true;
	            });
	    	} else {
	    		layer.msg(data.data, {
	    		    icon: 1,
	    		    time: 1000 //1秒关闭（如果不配置，默认是3秒）
	    		},function(){
	    			if (urlStr2=='?p=/Config/index') {
	    				window.location.reload();
	    			} else if(urlStr1=='index' || urlStr1=='showfield' || urlStr1=='ucenter') {
	    				window.location.href = "{php}echo $_SERVER['REQUEST_URI']{/php}";
	    			} else {
	    				window.history.back(-1);
	    			}
	    		    return true;
	    		});
	    	}
	    } else {
	        layer.msg(data.data, {icon: 2,time: 1000});
	    }
	}

	// 批量删除
	function comDo(data){
	    if (data.code == 1) {
	    	if (data.data=='批量删除成功！') {
	    		layer.confirm('您确定要删除选中的内容么？', {icon: 3, title:'提示'}, function(index){
	    			layer.msg(data.data, {
	    			    icon: 1,
	    			    time: 1000 //1秒关闭（如果不配置，默认是3秒）
	    			},function(){
	    				window.location.reload();
	    			    return true;
	    			});
	    		});
	    	} else {
	    		layer.msg(data.data, {
	    		    icon: 1,
	    		    time: 1000 //1秒关闭（如果不配置，默认是3秒）
	    		},function(){
	    			window.location.reload();
	    		    return true;
	    		});
	    	}
	    } else {
	        layer.msg(data.data, {icon: 2,time: 1000});
	    }
	}

	// 确认删除
	function confirm_delete(url){
	    layer.confirm('确认要删除信息吗?', {icon: 3, title:'提示'}, function(index){
	        //do something
	        $.ajax({
	            url:url,
	            success:function(data){
	                var data = JSON.parse(data);
	                if (data.code == 1) {
	                	layer.msg(data.data, {
	                	    icon: 1,
	                	    time: 1000 //1秒关闭（如果不配置，默认是3秒）
	                	},function(){
	                		window.location.reload();
	                	    return true;
	                	});
	                } else {
	                    layer.msg(data.data, {icon: 2,time: 1000});
	                }
	            }
	        });
	        layer.close(index);
	    });
	}

	// 清除缓存
	function clear_common(url,title){
	    layer.confirm(title, {icon: 3, title:'提示'}, function(index){
	        //do something
	        $.ajax({
	            url:url,
	            success:function(data){
	                var data = JSON.parse(data);
	                if (data.code == 1) {
	                	layer.msg(data.data, {
	                	    icon: 1,
	                	    time: 1000 //1秒关闭（如果不配置，默认是3秒）
	                	},function(){
	                		window.location.reload();
	                	    return true;
	                	});
	                } else {
	                    layer.msg(data.data, {icon: 2,time: 1000});
	                }
	            }
	        });
	        layer.close(index);
	    });
	}
</script>
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

</body>
</html>
